package cn.wzg.netbase;

import android.os.Bundle;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import cn.wzg.netbase.utils.HttpCallbackListener;
import cn.wzg.netbase.utils.HttpUtil;
import cn.wzg.netbase.utils.HttpsUtil;

public class HttpUtilCallActivity extends AppCompatActivity {
    private String link="https://campus.zzuli.edu.cn/portal-pc/pc/qy/index.html";
    private TextView tv_html;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_http_util_call);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        tv_html=findViewById(R.id.tv_html);
        //调用封装好的类，进行网络访问
//        HttpUtil.sendHttpRequest(link, new HttpCallbackListener() {
//            @Override
//            public void onFinish(String response) {//成功
//                //需要切换回主线程
//                //使用runOnUiThread可以代替Handler，进行线程间切换，局限性：只能在Activity中使用
//                runOnUiThread(new Runnable() {
//                    @Override
//                    public void run() {
//                        tv_html.setText(response);
//                    }
//                });
//            }
//
//            @Override
//            public void onError(Exception e) {//出错
//
//            }
//        });
        HttpsUtil.sendHttpRequest(this, link, new HttpCallbackListener() {
            @Override
            public void onFinish(String response) {
                tv_html.setText(response);
            }

            @Override
            public void onError(Exception e) {

            }
        });
    }
}